package com.example.microservices.inventory.repository;

import com.example.microservices.inventory.model.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductRepository {
    
    @Select("SELECT * FROM products")
    List<Product> findAll();
    
    @Select("SELECT * FROM products WHERE id = #{id}")
    Product findById(@Param("id") Long id);
    
    @Insert("INSERT INTO products(name, description, price, stock, category, status) " +
            "VALUES(#{name}, #{description}, #{price}, #{stock}, #{category}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(Product product);
    
    @Update("UPDATE products SET stock = #{stock} WHERE id = #{id}")
    void updateStock(@Param("id") Long id, @Param("stock") Integer stock);
    
    @Update("UPDATE products SET name = #{name}, description = #{description}, " +
            "price = #{price}, stock = #{stock}, category = #{category}, status = #{status} " +
            "WHERE id = #{id}")
    void update(Product product);
    
    @Delete("DELETE FROM products WHERE id = #{id}")
    void deleteById(@Param("id") Long id);
} 